<template>
    <view class="page">
        <view class="header">
            <view class="header-status"></view>
            <view class="header-main">
                <view class="header-left">
                    <u-icon name="arrow-left" color="#fff" size="22" @click="_toBack(1)"></u-icon>
                </view>
                <view class="header-title">岗位详情</view>
                <view class="header-right">
                    <u-icon :name="row.is_collect ? 'star-fill' : 'star'" color="#fff" size="22" @click="collect">
                    </u-icon>
                    <u-icon name="warning" color="#fff" size="24" style="margin-left: 15rpx;" @tap="report"></u-icon>
                </view>
            </view>
        </view>
        <view class="head">
            <view class="title lgTitle ">{{ row.title }}</view>
            <view class="infoLine md4Text lgrey " style="display: flex;align-items: center;">
                <text class="icon ">&#xe633;</text><text class="textInfo">{{row.prov}}{{row.city}}{{row.dist}}</text>
                <text class="icon ">&#xe60d;</text><text class="textInfo">{{row.zgxl}}</text>
                <text class="icon ">&#xe61b;</text><text>{{row.gzjy}} </text>

            </view>

            <view class="salary salaryText ">{{row.salary_min}}-{{row.salary_max}}K</view>
        </view>

        <!-- 职位详情 -->
        <view class="warp">
            <view class="title md2Title">职位详情</view>

            <view class="tags mdText Han">
                <view class="tag">{{row.position}}</view>
                <view class="tag">{{row.gzjy == '不限' ? '经验不限' : row.gzjy}}</view>
                <view class="tag">{{row.zgxl == '不限' ? '学历不限' : row.zgxl}}</view>
            </view>

            <view class="content">
                <view class="md8Text " style="white-space: pre-line;">{{row.desc}}</view>
            </view>

            <!--公司地点 -->
            <view class="company" v-if="row.company" @tap="inCompany">
                <view class="left">
                    <image :src="row.company.logo" mode=""></image>
                    <view class="name">
                        <text class="md2Title" style="line-height: 1.5;">{{ row.company.name }}</text>
                        <text class="md4Text lgrey">{{row.company.rzjd}} {{row.company.gsgm}}</text>
                    </view>
                </view>

                <view class="right">
                    <image src="../../../static/imgs/right.png" mode=""></image>
                </view>
            </view>

            <!-- 位置 -->
            <view class="mapView">
                <map id="map" style="width: 100%; height:100%;" :latitude="row.lat" :longitude="row.lng"
                    :markers="markers" :enable-scroll="false" @tap="goAddress">
                    <cover-view style="width: 100%;height: 100%;background-color: rgba(0,0,0,0);"
                        @click="goAddress"></cover-view>
                </map>
            </view>

            <!-- 安全提示 -->
            <view class="gap"></view>

            <view class="tips">
                <view style="display: flex;align-items: center;">
                    <image src="../../../static/imgs/safe.png" mode=""></image>
                    <view style="font-weight: bold;margin-left: 5rpx;">蓝鲸安全提示</view>
                </view>
                <view class="tipContent">
                    <text
                        class="mdText">蓝鲸微聘严禁用人单位做出任何损害求职者合法权益的违法违规行为，包括但不限于扣押求职者证件、收取求职者财物、向求职者集资、让求职者入股、诱导求职者异地入职、异地参与培训等，您一旦发现此类行为，</text>
                    <text class="report mdText" @tap="report">请立即举报</text>
                </view>
            </view>
        </view>

        <!-- 立即沟通 -->
        <view class="chat">
            <button type="default" class="btn submit" @tap="chat"><text>立即沟通</text></button>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                id: 0,
                row: {},
                markers: []
            };
        },
        onLoad(options) {
            this.id = options.id || 0;
            this.getJobDetail();
        },
        onReady() {

        },
        methods: {
            goAddress(e) {
                console.log(JSON.stringify(e));
                uni.openLocation({
                    latitude: this.row.lat * 1,
                    longitude: this.row.lng * 1,
                    address: this.row.address + ' ' + this.row.room,
                    name: this.row.company.name
                })
            },
            getJobDetail() {
                this._ajax({
                    url: '/api/index/getJobDetail',
                    data: {
                        id: this.id
                    },
                    success: res => {
                        if (res.code == 1) {
                            res.data.lat = parseFloat(res.data.lat);
                            res.data.lng = parseFloat(res.data.lng);
                            this.row = res.data;
                            this.markers = [{
                                id: 1,
                                latitude: this.row.lat,
                                longitude: this.row.lng,
                                iconPath: '/static/imgs/point.png',
                                width: 32,
                                height: 32,
                                callout: {
                                    content: this.row.company.name,
                                    borderRadius: 5,
                                    display: 'ALWAYS'
                                }
                            }];
                        } else {
                            this._toast(res.msg);
                        }
                    }
                }, 1);
            },
            collect() {
                this._ajax({
                    url: '/api/user/jobCollect',
                    data: {
                        job_id: this.id
                    },
                    success: res => {
                        this._toast(res.msg);
                        if (res.code == 1) {
                            this.row.is_collect = res.data;
                        }
                    }
                }, 1);
            },

            inCompany() {
                uni.navigateTo({
                    url: '/pages/views/detail/company?id=' + this.row.company_id
                });
            },
            report() {
                uni.navigateTo({
                    url: '/pages/views/detail/complaint?job_id=' + this.id
                });
            },
            chat() {
                this._ajax({
                    url: '/api/user/chat',
                    data: {
                        job_id: this.id
                    },
                    success: res => {
                        if (res.code == 1) {
                            uni.navigateTo({
                                url: '/pages/views/detail/chatBox?id=' + res.data
                            });
                        } else {
                            this._toast(res.msg);
                        }
                    }
                }, 1);
            }
        }
    };
</script>

<style scoped lang="less">
    .header {
        width: 100%;
        background-color: #3f6bb0;
        color: #fff;
        padding: 0 30rpx;
        z-index: 9;
        position: fixed;
        top: 0;
        left: 0;

        .header-status {
            height: var(--status-bar-height);
        }

        .header-main {
            height: 45px;
            display: flex;
            align-items: center;

            .header-left {
                position: fixed;
                left: 30rpx;
            }

            .header-title {
                flex: 1;
                font-size: 32rpx;
                text-align: center;
            }

            .header-right {
                position: fixed;
                right: 30rpx;
                display: flex;
                align-items: center;
            }
        }
    }

    .page {
        width: 750upx;
        margin: 0 auto;
        background-color: #f5f5f5;
        padding-top: calc(60px + var(--status-bar-height));

        .head {
            width: 100%;
            // height: 164upx;
            background-color: #ffffff;
            padding: 40rpx 30rpx;
            position: relative;

            .title {
                padding-bottom: 30rpx;
                font-weight: bold;
                padding-right: 120rpx;
                font-size: 40rpx;
                word-break: break-all;
            }

            .salary {
                color: #3f6bb0;
            }

            .infoLine {

                .textInfo {
                    padding-right: 30upx;
                }

                image {
                    width: 38upx;
                    height: 38upx;
                    vertical-align: middle;
                }
            }

            .salaryText {
                position: absolute;
                top: 40rpx;
                right: 30rpx;
            }
        }

        .warp {
            width: 100%;
            margin-top: 30rpx;
            padding: 30rpx;
            padding-bottom: 130rpx;
            background-color: #ffffff;

            .title {
                font-weight: bold;
            }

            .tags {
                display: flex;
                margin-top: 20rpx;

                .tag {
                    height: 45rpx;
                    line-height: 45rpx;
                    text-align: center;
                    background-color: #f3faff;
                    margin-right: 20upx;
                    padding: 0 20rpx;
                }
            }
        }

        .content {
            border-bottom: 1px solid #e5e5e5;
            padding-bottom: 50upx;
            margin-top: 20rpx;
            line-height: 2;

            .gap {
                height: 50upx;
            }

            .items {
                padding: 10upx 0;
            }
        }

        .company {
            width: 100%;
            margin-top: 25upx;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .left {
                display: flex;
                align-items: center;

                image {
                    width: 100rpx;
                    height: 100rpx;
                    border-radius: 50%;
                }

                .name {
                    flex: 1;
                    margin-left: 30upx;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    padding: 10upx 0;

                    text {
                        display: block;

                        &:nth-child(1) {
                            // padding-bottom: 20upx;
                        }
                    }
                }
            }

            .right {
                image {
                    width: 48upx;
                    height: 48upx;
                }
            }
        }

        .mapView {
            width: 100%;
            height: 400rpx;
            text-align: center;
            margin-top: 20rpx;
            position: relative;
        }

        .tips {
            view {
                image {
                    width: 40rpx;
                    height: 40rpx;
                }
            }

            .tipContent {
                margin-top: 24upx;
                width: 100%;

                text {
                    font-weight: normal !important;
                    line-height: 40upx;
                }

                .report {
                    color: #3465b1;
                    text-decoration: underline;
                }
            }
        }
    }

    .chat {
        width: 100%;
        height: 116upx;
        box-shadow: 0px -10px 80px rgba(167, 167, 167, 0.16);
        position: fixed;
        background-color: #ffffff;
        bottom: 0;
        padding-top: 15upx;
    }

    .icon {
        font-size: 30upx;
        padding-right: 10upx;
    }
</style>
<style>
    @import url("../../../static/css/iconfont.css");
</style>
